home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / liboctave / dbleHESS.cc < prev    next >
C/C++ Source or Header  |  1996-03-03  |  3KB  |  143 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if defined (__GNUG__)
  24. #pragma implementation
  25. #endif
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include <config.h>
  29. #endif
  30.  
  31. #include "dbleHESS.h"
  32. #include "f77-fcn.h"
  33. #include "lo-error.h"
  34. #include "mx-inlines.cc"
  35.  
  36. extern "C"
  37. {
  38.   int F77_FCN (dgebal, DGEBAL) (const char*, const int&, double*,
  39.                 const int&, int&, int&, double*,
  40.                 int&, long, long);
  41.  
  42.   int F77_FCN (dgehrd, DGEHRD) (const int&, const int&, const int&,
  43.                 double*, const int&, double*, double*,
  44.                 const int&, int&, long, long);
  45.  
  46.   int F77_FCN (dorghr, DORGHR) (const int&, const int&, const int&,
  47.                 double*, const int&, double*, double*,
  48.                 const int&, int&, long, long);
  49.  
  50.   int F77_FCN (dgebak, DGEBAK) (const char*, const char*, const int&,
  51.                 const int&, const int&, double*,
  52.                 const int&, double*, const int&, int&,
  53.                 long, long);
  54. }
  55.  
  56. int
  57. HESS::init (const Matrix& a)
  58. {
  59.   int a_nr = a.rows ();
  60.   int a_nc = a.cols ();
  61.  
  62.   if (a_nr != a_nc)
  63.     {
  64.       (*current_liboctave_error_handler) ("HESS requires square matrix");
  65.       return -1;
  66.     }
  67.  
  68.   char job = 'N';
  69.   char side = 'R';
  70.  
  71.   int n = a_nc;
  72.   int lwork = 32 * n;
  73.   int info;
  74.   int ilo;
  75.   int ihi;
  76.  
  77.   hess_mat = a;
  78.   double *h = hess_mat.fortran_vec ();
  79.  
  80.   Array<double> scale (n);
  81.   double *pscale = scale.fortran_vec ();
  82.  
  83.   F77_XFCN (dgebal, DGEBAL, (&job, n, h, n, ilo, ihi, pscale, info,
  84.                  1L, 1L));
  85.  
  86.   if (f77_exception_encountered)
  87.     (*current_liboctave_error_handler) ("unrecoverable error in dgebal");
  88.   else
  89.     {
  90.       Array<double> tau (n-1);
  91.       double *ptau = tau.fortran_vec ();
  92.  
  93.       Array<double> work (lwork);
  94.       double *pwork = work.fortran_vec ();
  95.  
  96.       F77_XFCN (dgehrd, DGEHRD, (n, ilo, ihi, h, n, ptau, pwork,
  97.                  lwork, info, 1L, 1L));
  98.  
  99.       if (f77_exception_encountered)
  100.     (*current_liboctave_error_handler) ("unrecoverable error in dgehrd");
  101.       else
  102.     {
  103.       unitary_hess_mat = hess_mat;
  104.       double *z = unitary_hess_mat.fortran_vec ();
  105.  
  106.       F77_XFCN (dorghr, DORGHR, (n, ilo, ihi, z, n, ptau, pwork,
  107.                      lwork, info, 1L, 1L));
  108.  
  109.       if (f77_exception_encountered)
  110.         (*current_liboctave_error_handler)
  111.           ("unrecoverable error in dorghr");
  112.       else
  113.         {
  114.           F77_XFCN (dgebak, DGEBAK, (&job, &side, n, ilo, ihi,
  115.                      pscale, n, z, n, info, 1L, 1L));
  116.  
  117.           if (f77_exception_encountered)
  118.         (*current_liboctave_error_handler)
  119.           ("unrecoverable error in dgebak");
  120.           else
  121.         {
  122.           // If someone thinks of a more graceful way of doing
  123.           // this (or faster for that matter :-)), please let
  124.           // me know!
  125.  
  126.           if (n > 2)
  127.             for (int j = 0; j < a_nc; j++)
  128.               for (int i = j+2; i < a_nr; i++)
  129.             hess_mat.elem (i, j) = 0;
  130.         }
  131.         }
  132.     }
  133.     }
  134.  
  135.   return info;
  136. }
  137.  
  138. /*
  139. ;;; Local Variables: ***
  140. ;;; mode: C++ ***
  141. ;;; End: ***
  142. */
  143.